/*
 * This file is part of b.AMP.
 *
 * b.AMP is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * b.AMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with b.AMP.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __BAMP_SERVICE_HPP__
#define __BAMP_SERVICE_HPP__

#include "runnable.hpp"
#include "message_source.hpp"
#include "message_target.hpp"
#include <bamp/noncopyable.hpp>

#include <memory>


namespace bamp
{

    class MessageLoop;


    class Service : public Runnable, public MessageSource,
                    public MessageTarget, public bamp::Noncopyable
    {
    public:
    
        Service();
        virtual ~Service();

        virtual bool run();
        virtual void stop();
        virtual void waitStop();
        virtual bool isRunning();
        virtual bool isStopping();

        virtual void setTarget(MessageTarget& target);
        virtual void clearTarget();

        virtual void send(const Message& message, MessageAck ack);
        virtual MessageAck send(const Message& message);

        MessageLoop* thread();
        MessageTarget* target();


    private:
    
        struct Implementation;
        std::auto_ptr<Implementation> pimpl;

    };

} // namespace bamp

#endif // __BAMP_SERVICE_HPP__
